package com.example.demo.repository;

import com.example.demo.model.College;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;

@Repository
public interface CollegeRepository extends JpaRepository<College, Long> {
    Optional<College> findByCode(String code);
    List<College> findByNameContaining(String name);
    Page<College> findByStatus(College.Status status, Pageable pageable);
    
    // 添加按名称模糊搜索并分页的方法
    Page<College> findByNameContaining(String name, Pageable pageable);
    
    // 添加按名称和状态组合搜索的方法
    @Query("SELECT c FROM College c WHERE (:name IS NULL OR c.name LIKE %:name%) AND (:status IS NULL OR c.status = :status)")
    Page<College> findByNameContainingAndStatus(@Param("name") String name, @Param("status") College.Status status, Pageable pageable);
    
    // 添加按名称查找的方法（用于导入功能）
    Optional<College> findByName(String name);
}